import axios from "axios";
import nprogress from "nprogress";
import "nprogress/nprogress.css";
import store from "@/store";
let requests = axios.create({
  // baseURL: "/api",
  // timeout: 5000,
  timeout: 5000,
});

// 请求拦截器
requests.interceptors.request.use((config) => {
  nprogress.start();
  config.headers["token"] = store.state.user.token;
  return config;
});

// 响应拦截器
requests.interceptors.response.use(
  (res) => {
    nprogress.done();
    return res.data;
  },
  (err) => {
    if (err.code == "ERR_NETWORK") {
      alert("兄弟代理跨域你没整")
  }
    return Promise.reject();
  }
);

export default requests;
